package psn.kiko.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import psn.kiko.aop.debounce.Debounce;
import psn.kiko.pojo.PageDTO;
import psn.kiko.pojo.R;
import psn.kiko.pojo.dto.UserDTO;
import psn.kiko.service.UserService;

/**
 * 2024/11/10 13:11
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户管理")
@RequiredArgsConstructor
public class UserController{
	private final UserService userService;
	
	@PostMapping
	@ApiOperation("添加用户")
	public R<?> addUser(@RequestBody @ApiParam("待添加的用户") UserDTO dto){
		return userService.addUser(dto);
	}
	
	@Debounce//此接口已标记防抖
	@GetMapping("{id}")
	@ApiOperation("根据主键获取用户")
	public R<?> getUserById(@PathVariable("id") Integer id){
		return userService.getUserById(id);
	}
	
	@Debounce(value = 2000L)
	@DeleteMapping({"{id}"})
	@ApiOperation("根据主键删除用户")
	public R<?> deleteUserById(@PathVariable("id") Integer id){
		return userService.deleteUserById(id);
	}
	
	@PutMapping
	@ApiOperation("根据主键修改用户")
	public R<?> updateUser(@RequestBody UserDTO dto){
		return userService.updateUserById(dto);
	}
	
	@PostMapping("page")
	@ApiOperation("分页根据条件获取用户")
	public R<?> pageUser(@RequestBody PageDTO<UserDTO> pageDto){
		return userService.pageUser(pageDto);
	}
}
